import gevent


def talk(msg):
    print(msg)
    gevent.sleep(0)
    print(msg)

def test_sleep1():
    g1 = gevent.spawn(talk, 'bar')
    g1.join()

def test_sleep2():
    g1 = gevent.spawn(talk, 'bar')
    gevent.sleep(0)

def test_switch():
    def beep(interval):
        while True:
            print("Beep %s" % interval)
            gevent.sleep(interval)

    for i in range(10):
        gevent.spawn(beep, i+8)

    beep(20)


if __name__ == '__main__':
    # test_sleep1()
    test_switch()